var app = getApp();

var drawProgress = require("../../js/drawcircle.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    selectindex:0,
    totalydpm:0,
    myinfo:{},//我的答题情况

    jfph: {
      page: 1,
      limit: 20,
      totalpage: 0,
      datas: []
    },
    jfph1: [],
    jfph2: [],
    totalydpm: 0,
    bid: '',

    mypm:0,//我的排名
    myjf:'',//我的积分
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var usid = wx.getStorageSync('usid');
    if (!usid) {
      wx.reLaunch({
        url: '../../pages/login/login'
      })
      return;
    }
    this.setData({
      bid: options.bid,
      usid: usid
    })
    //查询用户的答题情况
    this.getUserDtqk();
    //查询大会荣誉榜
    this.getpmBynj();

  },

  getUserDtqk(){
    var that = this;
    var bid = that.data.bid;
    var usid = that.data.usid;
    app.wxget({
      url: 'wscdh/getUserDtqk.html',
      data: {
        bid: bid,
        usid: usid
      },
      success: function (res) {
        var datas = res.data;
        that.setData({
          myinfo: datas
        })
        console.log(datas);
        //x坐标，y坐标，r半径，计数器最大值60,对应 2
        drawProgress.drawProgress(75, 75, 65, datas.zql1);

      }
    })
  },

  getpmBynj() {
    var that = this;
    var bid = that.data.bid;
    var usid = that.data.usid;
    var page = that.data.jfph.page;
    var limit = that.data.jfph.limit;
    var totalpage = that.data.jfph.totalpage;
    if (page != 1) {
      if (page > totalpage) {
        return;
      }
    } 

    app.wxget({
      url: 'wscdh/getscdhPmBynj.html',
      data: {
        bid: bid,
        usid: usid,
        page: page,
        limit: limit,
      },
      success: function (res) {
        //积分排名
        var jfph = that.data.jfph;
        var datas = jfph.datas;

        var jfp = res.data.list;
        var totalpage = res.data.totalpage;

        //前三名
        var jfph1 = [];
        //除去前三名的
        var jfph2 = [];

        for (var i = 0; i < jfp.length; i++) {
          datas.push(jfp[i]);
        }
  
        for (var j = 0; j < datas.length; j++) {
          var pm = parseInt(datas[j].PM);
          if (pm <= 3) {
            jfph1.push(datas[j]);
          } else {
            jfph2.push(datas[j]);
          }
          if (datas[j].USID==usid){
            that.setData({
              mypm: datas[j].PM,
            })
          } 
        }

        jfph.datas = datas;
        jfph.totalpage = totalpage;
        that.setData({
          jfph: jfph,
          jfph1: jfph1,
          jfph2: jfph2,
          totalydpm: res.data.totalnum,
        })


      }
    })
  },

  changeshow(){
    var selectindex = this.data.selectindex;
    if (selectindex==0){
      this.setData({
        selectindex:1
      })
    }else{
      this.setData({
        selectindex:0
      })
    }
  },

  lookStDA() {
    wx.redirectTo({
      url: '../../pages/scdhda/scdhda?bid=' + this.data.bid
    })
  }

})